package com.example.spareparts.repository;

import com.example.spareparts.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserRepository  {
    @Select("SELECT * FROM Users" )
    List<User> findAllUser();

    @Insert("INSERT INTO Users (username, password, role) VALUES (#{username}, #{password}, #{role})")
    @Options(useGeneratedKeys = true, keyProperty = "userid")
    void insertUser(User user);

    @Update("UPDATE Users SET username=#{username}, password=#{password}, role=#{role} WHERE user_id=#{userid}")
    void updateUser(User user);

    @Delete("DELETE FROM Users WHERE user_id=#{userid}")
    void deleteUser(Long userid);
    @Select("SELECT * FROM Users WHERE user_id= #{userid}")
    User findUserById(Long userid);
    @Select("SELECT * FROM Users WHERE username= #{username}")
    User findUserByUsername(String username);
}